<template>
  <div>
    <zh-form  ref="formInfo" :colmun="1" :rules="rules" :model="formInfo"  labelAlign="right" >

      <zh-card style="width:100%">

        <zh-row>
          <zh-input prop="taskArea" type="tree" mode="multiple" label="执行区域"  placeholder="支持多选"
                    allowClear
                    tree-checkable
                    multiple
                    v-model="formInfo.taskArea"
                    :treeData="taskAreaTree"
                    :showCheckedStrategy = "SHOW_PARENT"
                    :span="22"
                    style="float: left"
                    :labelCol="{span:3}" :wrapperCol="{span:16}"
                    @change="taskAreaChange"
          >
          </zh-input>
        </zh-row>
        <zh-row>
<!--          <zh-input prop="d0215"  :span="22" type="select"  mode="multiple" :options="dictData.b0105"
                    label="文物等级" v-model="formInfo.d0215" :labelCol="{span:3}" :wrapperCol="{span:16}"
                    placeholder="请选择文物等级(可多选)" @change="d0215Change" :disabled="d0215Disabled"></zh-input>-->
          <zh-input prop="d0215" type="tree" mode="multiple" label="文物等级"  placeholder="支持多选"
                    allowClear
                    tree-checkable
                    multiple
                    v-model="formInfo.d0215"
                    :treeData="treeData.b0105"
                    :showCheckedStrategy = "SHOW_PARENT"
                    :span="22"
                    style="float: left"
                    :labelCol="{span:3}" :wrapperCol="{span:16}"
                    :replaceFields="{children:'children', title:'title', key:'key', value: 'value' }"
                    @change="d0215Change"
                    :disabled="d0215Disabled"
          >
          </zh-input>
        </zh-row>

        <zh-row>
<!--          <zh-input prop="d0216"  :span="22" type="select"  mode="multiple" :options="dictData.b0129"
                    label="巡查级别" v-model="formInfo.d0216" :labelCol="{span:3}" :wrapperCol="{span:16}"
                    placeholder="请选择巡查级别(可多选)" @change="d0216Change" :disabled="d0216Disabled"></zh-input>-->
          <zh-input prop="d0216" type="tree" mode="multiple" label="巡查级别"  placeholder="支持多选"
                    allowClear
                    tree-checkable
                    multiple
                    v-model="formInfo.d0216"
                    :treeData="treeData.b0129"
                    :showCheckedStrategy = "SHOW_PARENT"
                    :span="22"
                    style="float: left"
                    :labelCol="{span:3}" :wrapperCol="{span:16}"
                    :replaceFields="{children:'children', title:'title', key:'key', value: 'value' }"
                    @change="d0216Change"
                    :disabled="d0216Disabled"
          >
          </zh-input>
        </zh-row>

        <zh-row>
<!--          <zh-input prop="d0217"  :span="22" type="select"  mode="multiple" :options="dictData.b0104"
                    label="类别" v-model="formInfo.d0217" :labelCol="{span:3}" :wrapperCol="{span:16}"
                    placeholder="请选择类别(可多选)"></zh-input>-->
          <zh-input prop="d0217" type="tree" mode="multiple" label="类别"  placeholder="支持多选"
                    allowClear
                    tree-checkable
                    multiple
                    v-model="formInfo.d0217"
                    :treeData="treeData.b0104"
                    :showCheckedStrategy = "SHOW_PARENT"
                    :span="22"
                    style="float: left"
                    :labelCol="{span:3}" :wrapperCol="{span:16}"
                    :replaceFields="{children:'children', title:'title', key:'key', value: 'value' }"
          >
          </zh-input>
        </zh-row>

        <zh-row>
          <a-col :span="22">
            <a-form-model-item label="巡查频率" prop="d0207" :labelCol="{span:3}" :wrapperCol="{span:18}">
              <a-select
                  style="width: 4vw;"
                  v-model="formInfo.d0207"
                  @change="planTypeChange"
              >
                <a-select-option
                    v-for="(item, index) in this.d0207Dict"
                    :value="item.dictKey"
                    :key="index"
                >{{ item.dictValue }}</a-select-option
                >
              </a-select>
              <div style="display: inline-block;margin-left: 5px">
                <a-input-number id="d0208" v-model="formInfo.d0208" @change="d0208Change" :min=d0208Min :max=d0208Max />
                <label style="color: black;margin-bottom: 2px"> 次 </label>
              </div>
              <div style="display: inline-block; margin-bottom: 20px;margin-left: 5px" v-show="d0209Show">
                <label style="color: black;">每次间隔 </label>
                <a-input-number id="d0209" v-model="formInfo.d0209" @change="d0209Change" :disabled="d0209Disabled" :min=d0209Min :max=d0209Max />
                <label style="color: black;"> 天 </label>
              </div>
            </a-form-model-item>
          </a-col>
        </zh-row>

        <!--        <zh-row>
                  <div style="margin-bottom: 20px" v-show="d0212Show">
                  <label style="color: black;">是否跳过周末：</label>
                  <a-radio-group name="d0212Radio" v-model="formInfo.d0212" @change="d0212Change">
                    <a-radio value="1">跳过周末</a-radio>
                    <a-radio value="0">包括周末</a-radio>
                  </a-radio-group>
                  </div>
                </zh-row>-->
      </zh-card>

    </zh-form>


    <div v-show="isSpecial">
      <zh-card style="width:100%" title="专题表单配置">
        <ep-button
            :size="size"
            style="margin-left: 15px"
            @click="
            () => {
              this.getDefaultConfig();
            }
          "
        >获取默认配置</ep-button
        >
        <a-form-model
            ref="specialFormVOS"
            :label-col="labelCol"
            :wrapper-col="wrapperCol">
          <a-form-model-item label="表单名称">
            <a-input :size="size" style="width: 50%" v-model="formInfo.d0218" />
          </a-form-model-item>

          <a-form-model-item
              v-for="(item, index) in formInfo.specialFormVOS"
              :key="index"
          >
            <div class="list-item">
              <div class="list-item-index">{{ index + 1 }}.</div>
              <a-input
                  :size="size"
                  v-model="item.d0803"
                  placeholder="请输入"
                  style="width: 50%; margin-right: 8px"
              />
              <!--<ep-button v-if="formInfo.specialFormVOS.length > 0"-->
              <!--            style="margin-left: 15px;"-->
              <!--           type="danger" icon="del.svg" @click="removeSpecialInfo(index)">-->
              <!--  删除-->
              <!--</ep-button>-->
              <a-button :size="size" type="link" icon="delete" @click="removeSpecialInfo(index)">删除</a-button>
              <a-select
                  :size="size"
                  style="width: 7vw;margin-left: 15px"
                  v-model="item.d0802"
                  @change="patrolTypeChange(item,index)"
              >
                <a-select-option
                    v-for="(item3, index3) in d0802Dict"
                    :value="item3.dictKey"
                    :key="index3"
                >{{ item3.dictValue }}</a-select-option
                >
              </a-select>
              <a-checkbox :size="size" style="margin-left: 15px" v-model="item.d0804">必填</a-checkbox>
            </div>

            <a-form-model class="sub-form" ref="optionList" :model="item.optionList"
                    :label-col="labelCol" :wrapper-col="wrapperCol">
              <a-form-model-item
                  v-for="(item2, index2) in item.optionList"
                  :key="index2"
                  :label="item2.label"
              >
                <div class="list-item">
                  <a-input
                      v-model="item2.d0902"
                      :size="size"
                      placeholder="请输入选项名称"
                      style="width: 40%; margin-right: 8px"
                      @blur="d0902Change"
                  />
                  <a-button :size="size" type="link" icon="delete" @click="removeOption(index2,index)">删除</a-button>
                  <a-checkbox :size="size" @change="d0903Change" v-if="item2.d0903 != null"  style="margin-left: 15px" v-model="item2.d0903">设为默认项</a-checkbox>
                </div>
              </a-form-model-item>

            </a-form-model>
            <div v-if="item.d0802 === '4' || item.d0802 === '5'">
              <a-button :size="size" type="link" icon="plus" @click="addOption(item,index)">添加单项</a-button>
              <a-divider type="vertical" />
              <a-button :size="size" type="link" @click="addOptionOther(item,index)">添加其他</a-button>
            </div>
          </a-form-model-item>
          <a-form-model-item >
            <a-button type="dashed" icon="plus" style="width: 50%" @click="addSpecialInfo">添   加</a-button>
          </a-form-model-item>
        </a-form-model>
      </zh-card>

    </div>
  </div>
</template>

<script>
import modal from 'ant-design-vue/es/modal'
import {getBatchDict} from "@/services/system/api"
import {getPatrolSettingRes, getPermissionParams,getDictByC0303Area,getSpecialDefaultConfig} from '@/services/system/whdngxlApi'
import {TreeSelect} from "ant-design-vue";
import moment from "moment";
import {mapGetters} from "vuex";

const SHOW_PARENT = TreeSelect.SHOW_PARENT;
export default {
  components:{
  },
  computed: {
    ...mapGetters(['size']),
  },
  props:{
    setPatrolData:{
      type:Function,
      default:null
    },
    setPatrolDataTwo:{
      type:Function,
      default:null
    }
  },
  data() {
    return {
      formInfo:{
        d0201:'',
        d0706:'',
        c0303:'',
        d0703:'',
        d0704:null,
        taskArea:undefined,
        d0215:undefined,
        d0216:undefined,
        d0217:undefined,
        d0207:'',
        d0208:'',
        d0209:'',
        d0212:'0',
        d0218:'',
        specialFormVOS:[],
        specialFormVOSDel:[],
        beforeChooseCount:null,//记录编辑前的点位数量
        resourcesData:[],
      },
      rules:{},
      dictData: {
        b0105:[],
        b0104:[],
        b0129:[],
      },
      treeData: {
        b0105:[],
        b0104:[],
        b0129:[],},
      taskAreaTree:[],
      SHOW_PARENT,
      visible: false,
      d0208Max:6,
      d0208Min:1,
      d0208Type:'天',
      d0209Max:0,
      d0209Min:0,
      d0209Show:true,
      // d0212Show:true,
      d0209Disabled:false,
      d0207Dict:[
        {dictKey:"1",dictValue:"天"},
        {dictKey:"2",dictValue:"周"},
        {dictKey:"3",dictValue:"月"},
        {dictKey:"5",dictValue:"季"},
        {dictKey:"4",dictValue:"年"}
      ],
      d0802Dict:[
        {dictKey:"1",dictValue:"数字"},
        {dictKey:"2",dictValue:"文本"},
        {dictKey:"3",dictValue:"日期"},
        {dictKey:"4",dictValue:"选项(单选)"},
        {dictKey:"5",dictValue:"选项(多选)"},
        {dictKey:"6",dictValue:"多媒体"},
        {dictKey:"7",dictValue:"定位"},
        {dictKey:"8",dictValue:"手机号"},
      ],
      d0215Disabled:false,
      d0216Disabled:false,
      warnInfoFlag:false,
      pointFlag:false,//是否从巡查清单页面打开
      isSpecial:false,
      labelCol: { span: 2 },
      wrapperCol: { span: 22 },


    }
  },

  created() {

    //获取任务范围
    this.$http.post(getPermissionParams, {}).then(res => {
      const data = res.result
      this.taskAreaTree = data.orgTreeData
    })
  },
  methods: {
    initData(data,pointFlag){
      this.formInfo.d0706 = data.d0706
      this.formInfo.c0303 = data.c0303
      this.formInfo.d0703 = data.d0703
      this.formInfo.d0704 = data.d0704
      this.pointFlag = pointFlag //该标记表示是从任务清单页面跳转而来
      //专项任务
      this.isSpecial = this.formInfo.d0706 == '2'

      //编辑
      if(data.d0206){
        // this.formInfo = data
        if(data.d0201){
          this.formInfo.d0201 = data.d0201
        }
        this.formInfo.taskArea = data.taskArea
        if(data.d0215){
          this.formInfo.d0215 = data.d0215
        }
        if(data.d0216){
          this.formInfo.d0216 = data.d0216
        }
        this.formInfo.d0217 = data.d0217
        this.formInfo.d0207 = data.d0207
        this.formInfo.d0208 = data.d0208
        if(data.d0209){
          this.formInfo.d0209 = data.d0209
        }
        if(data.d0218){
          this.formInfo.d0218 = data.d0218
        }
        if(data.specialFormVOS){
          this.formInfo.specialFormVOS = data.specialFormVOS

        }
        this.formInfo.beforeChooseCount = data.pointCount
        //编辑时初始化
        this.planTypeCheck()
        // this.d0212Check()
        this.d0208Check()
        this.d0215Change()
        this.d0216Change()
        this.getTreeData()
      }
    },
    getDefaultConfig(){
      this.$http.post(getSpecialDefaultConfig, {}).then(res => {
        this.formInfo.d0218 = '专项巡查默认表单'
        this.formInfo.specialFormVOS = res.result.specialFormVOS
      })
    },
    getTreeData(){
      if(this.formInfo.taskArea!==undefined && this.formInfo.taskArea.length>0){
        const param = Object.assign(this.formInfo)
        this.$http.post(getDictByC0303Area, param).then(res => {
          this.dictData = res.result
          //添加下拉数数据
          let keyArr = Object.keys(this.dictData);
          for (let i = 0; i < keyArr.length; i++) {
            let treeKey = keyArr[i];
            let treeParam = this.dictData[treeKey];
            if(treeParam.length>0){
              let title = ''
              switch (treeKey){
                case 'b0105' : title = "全部文物等级"
                  break
                case 'b0104' : title = "全部古系列类别"
                  break
                case 'b0129' : title = "全部巡查级别"
                  break
              }
              let treeObj = {title:title,value:'00',key:'00'};
              let children = []
              for (let j = 0; j < treeParam.length; j++) {
                let treeArr = {
                  key: treeParam[j].dictKey,
                  value: treeParam[j].dictKey,
                  title:treeParam[j].dictValue,
                };
                children.push(treeArr);
              }
              treeObj.children = children
              this.treeData[treeKey].push(treeObj)
            }
          }
        })
      }
    },
    d0902Change(){
      this.$forceUpdate(); //重新强制渲染
    },
    d0903Change(){
      this.$forceUpdate(); //重新强制渲染
    },
    //移除专项表单内容
    removeSpecialInfo(index){
      modal.confirm({
        title: "确认删除吗？",
        onOk: () => {
          if (this.formInfo.specialFormVOS[index].d0801) {
            const item = JSON.parse(JSON.stringify(this.formInfo.specialFormVOS[index]));
            this.formInfo.specialFormVOSDel.push(item);
          }
          this.formInfo.specialFormVOS.splice(index, 1);
        },
        onCancel: () => {},
      })
    },
    //添加专项表单内容
    addSpecialInfo(){

      this.formInfo.specialFormVOS.push({
        d0802: '',
        d0803: '',
        d0804: true,
      })
    },
    //移除单选项多选项内容
    removeOption(index2,index){
      if(this.formInfo.specialFormVOS[index].optionListDel === null || this.formInfo.specialFormVOS[index].optionListDel === undefined){
        this.formInfo.specialFormVOS[index].optionListDel = []
      }

      let length = this.formInfo.specialFormVOS[index].optionList.length
      for(let i = 0;i<length;i++){
        if(this.formInfo.specialFormVOS[index].optionList[i].d0904 === '1'){
          length = length -1
        }
      }

      if(this.formInfo.specialFormVOS[index].optionList[index2].d0904 !== '1' && length<=2){
        this.$message.warn( "选项至少需要保留两个！");
        return
      }

      modal.confirm({
        title: "确认删除吗？",
        onOk: () => {
          if (this.formInfo.specialFormVOS[index].optionList[index2].d0901) {
            const item = JSON.parse(JSON.stringify(this.formInfo.specialFormVOS[index].optionList[index2]));
            this.formInfo.specialFormVOS[index].optionListDel.push(item);
          }
          this.formInfo.specialFormVOS[index].optionList.splice(index2,1)
          this.$forceUpdate(); //重新强制渲染
        },
        onCancel: () => {},
      })
    },
    //添加单选项多选项内容
    addOption(item,index){
      let length = 0; //排除其他后的选项个数
      for(let i = 0; i<this.formInfo.specialFormVOS[index].optionList.length;i++){
        if(this.formInfo.specialFormVOS[index].optionList[i].d0904 !== '1'){
          length = length+1
        }
      }
      let num = length+1
      let option = {}
      if(item.d0802 === '4'){
        option = {label:'选项'+num,d0902:'',d0903:false}
      }else{
        option = {label:'选项'+num,d0902:'',}
      }

      this.formInfo.specialFormVOS[index].optionList.push(JSON.parse(JSON.stringify(option)))
      this.$forceUpdate(); //重新强制渲染
    },
    //添加“其他”选项
    addOptionOther(item,index){
      for(let i = 0;i<this.formInfo.specialFormVOS[index].optionList.length;i++){
        let option = this.formInfo.specialFormVOS[index].optionList[i]
        if(option.d0904 === '1'){
          this.$message.warn( "已经有其他选项，不能再添加！");
          return
        }
      }
      const optionOther = {label:'其他',d0902:'',d0904:'1'}
      this.formInfo.specialFormVOS[index].optionList.push(JSON.parse(JSON.stringify(optionOther)))
      this.$forceUpdate(); //重新强制渲染
    },
    //日期选择器禁用的日期
    onDisabledDate(current){
      const time = moment().endOf('day').subtract(1, 'days')
      return current < time
    },
    //巡查类型d0802改变事件
    patrolTypeChange(item,index){
      this.formInfo.specialFormVOS[index].optionList = []

      if(item.d0802 === '4' || item.d0802 === '5'){
        let defaultOption=[]
        if(item.d0802 === '4'){
          defaultOption=[{label:'选项1',d0902:'',d0903:false},{label:'选项2',d0902:'',d0903:false}]
        }else{
          defaultOption=[{label:'选项1',d0902:''},{label:'选项2',d0902:''}]
        }

        this.formInfo.specialFormVOS[index].optionList = JSON.parse(JSON.stringify(defaultOption))
      }
    },
    //计划类型改变事件
    planTypeChange(){
      if(this.formInfo.d0201 && this.warnInfoFlag === false){
        modal.warn({title: '提示', content: '巡查频率修改后前期任务全部算完成'})
        this.warnInfoFlag = true
      }
      this.d0209Show = true
      // this.d0212Show = true
      this.d0209Disabled = false
      this.d0208Max = 6
      this.d0208Min = 1
      this.d0209Max = 0
      this.d0209Min = 0
      this.formInfo.d0208 = ''
      this.formInfo.d0209 = ''
      this.formInfo.d0212 = '0'
      this.planTypeCheck()
    },
    planTypeCheck(){
      if(this.formInfo.d0207){
        switch (this.formInfo.d0207){
            //按天没有执行间隔这个字段，执行频率至少1次，最多3次
          case '1' :
            this.d0208Type = "天"
            this.d0209Show = false
            this.d0208Max = 3
            break
          case '2' :
            this.d0208Type = "周"
            break
            //按月，按年，没有是否跳过周末这个字段，默认就是包括周末
          case '3':
            this.d0208Type = "月"
            // this.d0212Show = false
            this.d0208Max = 31
            this.d0209Max = 31
            this.d0209Min = 1
            break
          case '4':
            this.d0208Type = "年"
            // this.d0212Show = false
            this.d0208Max = 365
            this.d0209Max = 365
            this.d0209Min = 1
            break
          case '5':
            this.d0208Type = "季"
            // this.d0212Show = false
            this.d0208Max = 90
            this.d0209Max = 90
            this.d0209Min = 1
            break
        }
      }
    },
    //执行频率改变事件
    d0208Change(){
      if(this.formInfo.d0201 && this.warnInfoFlag === false){
        modal.warn({title: '提示', content: '巡查频率修改后前期任务全部算完成'})
        this.warnInfoFlag = true
      }
      if(this.formInfo.d0207 == '2'){ //每周
        this.d0209Show = true
        this.d0209Disabled = false
        this.formInfo.d0209 = ''
        this.d0209Max = 3
        this.d0209Min = 0
        if(this.formInfo.d0212){
          if(this.formInfo.d0212 == '0'){ //包括周末
            switch (this.formInfo.d0208){
              case 1:
                this.d0209Show = false
                this.formInfo.d0209 = ''
                break
              case 2:
                this.d0209Max = 3
                this.d0209Min = 0
                break
              case 3:
                this.d0209Max = 2
                this.d0209Min = 0
                break
              case 4:
                this.d0209Max = 1
                this.d0209Min = 0
                break
              case 5:
              case 6:
                this.formInfo.d0209 = 0
                this.d0209Disabled = true
                break
            }
          }else if(this.formInfo.d0212 == '1'){//不包括周末
            switch (this.formInfo.d0208){
              case 1:
                this.d0209Show = false
                this.formInfo.d0209 = ''
                break
              case 2:
                this.d0209Max = 2
                this.d0209Min = 0
                break
              case 3:
                this.d0209Max = 1
                this.d0209Min = 0
                break
              case 4:
                this.formInfo.d0209 = 0
                this.d0209Disabled = true
                break
            }
          }
        }
      }else if(this.formInfo.d0207 == '3'){ //每月 执行频率和执行间隔乘积不能超过31
        if(this.formInfo.d0208 * this.formInfo.d0209>31){
          this.formInfo.d0208 = ''
          this.formInfo.d0209 = ''
          modal.warn({title: '提示', content: '每月的情况下，执行频率和执行间隔乘积不能超过31'})
        }
        if(this.formInfo.d0208 === 1){
          this.d0209Show = false
          this.formInfo.d0209 = ''
        }else{
          this.d0209Show = true
        }
      }else if(this.formInfo.d0207 == '4'){//每年 执行频率和执行间隔乘积不能超过365
        if(this.formInfo.d0208 * this.formInfo.d0209>365){
          this.formInfo.d0208 = ''
          this.formInfo.d0209 = ''
          modal.warn({title: '提示', content: '每年的情况下，执行频率和执行间隔乘积不能超过365'})
        }
        if(this.formInfo.d0208 === 1){
          this.d0209Show = false
          this.formInfo.d0209 = ''
        }else{
          this.d0209Show = true
        }
      }else if(this.formInfo.d0207 == '5'){
        if(this.formInfo.d0208 * this.formInfo.d0209>90){
          this.formInfo.d0208 = ''
          this.formInfo.d0209 = ''
          modal.warn({title: '提示', content: '每季的情况下，执行频率和执行间隔乘积不能超过90'})
        }
        if(this.formInfo.d0208 === 1){
          this.d0209Show = false
          this.formInfo.d0209 = ''
        }else{
          this.d0209Show = true
        }
      }
    },
    d0208Check(){
      if(this.formInfo.d0207 == '2'){ //每周
        this.d0209Show = true
        this.d0209Disabled = false
        this.d0209Max = 3
        this.d0209Min = 0
        if(this.formInfo.d0212){
          if(this.formInfo.d0212 == '0'){ //包括周末
            switch (this.formInfo.d0208){
              case 1:
                this.d0209Show = false
                break
              case 2:
                this.d0209Max = 3
                this.d0209Min = 0
                break
              case 3:
                this.d0209Max = 2
                this.d0209Min = 0
                break
              case 4:
                this.d0209Max = 1
                this.d0209Min = 0
                break
              case 5:
              case 6:
                this.formInfo.d0209 = 0
                this.d0209Disabled = true
                break
            }
          }else if(this.formInfo.d0212 == '1'){//不包括周末
            switch (this.formInfo.d0208){
              case 1:
                this.d0209Show = false
                break
              case 2:
                this.d0209Max = 2
                this.d0209Min = 0
                break
              case 3:
                this.d0209Max = 1
                this.d0209Min = 0
                break
              case 4:
                this.formInfo.d0209 = 0
                this.d0209Disabled = true
                break
            }
          }
        }
      }else if(this.formInfo.d0207 == '3'){ //每月 执行频率和执行间隔乘积不能超过31
        this.d0209Show = this.formInfo.d0208 !== 1;
      }else if(this.formInfo.d0207 == '4'){//每年 执行频率和执行间隔乘积不能超过365
        this.d0209Show = this.formInfo.d0208 !== 1;
      }else if(this.formInfo.d0207 == '5'){//每季 执行频率和执行间隔乘积不能超过90
        this.d0209Show = this.formInfo.d0208 !== 1;
      }
    },
    /* //跳过周末事件
     d0212Change(){
       if(this.formInfo.d0207 == '2'){ //每周
         this.formInfo.d0208 = ''
         this.formInfo.d0209 = ''
         if(this.formInfo.d0212 == '1'){ //跳过周末
           this.d0208Max = 4
         }else if(this.formInfo.d0212 == '0'){ //包括周末
           this.d0208Max = 6
         }
       }
     },
     d0212Check(){
       if(this.formInfo.d0207 == '2'){ //每周
         if(this.formInfo.d0212 == '1'){ //跳过周末
           this.d0208Max = 4
         }else if(this.formInfo.d0212 == '0'){ //包括周末
           this.d0208Max = 6
         }
       }
     },*/
    //执行间隔事件
    d0209Change(){
      if(this.formInfo.d0207 == '3'){
        if(this.formInfo.d0208 * this.formInfo.d0209>31){
          this.formInfo.d0208 = ''
          this.formInfo.d0209 = ''
          modal.warn({title: '提示', content: '每月的情况下，执行频率和执行间隔乘积不能超过31'})
        }
      }else if(this.formInfo.d0207 == '4'){//每年 执行频率和执行间隔乘积不能超过365
        if(this.formInfo.d0208 * this.formInfo.d0209>365){
          this.formInfo.d0208 = ''
          this.formInfo.d0209 = ''
          modal.warn({title: '提示', content: '每月的情况下，执行频率和执行间隔乘积不能超过365'})
        }
      }else if(this.formInfo.d0207 == '5'){//每季度
        if(this.formInfo.d0208 * this.formInfo.d0209>90){
          this.formInfo.d0208 = ''
          this.formInfo.d0209 = ''
          modal.warn({title: '提示', content: '每月的情况下，执行频率和执行间隔乘积不能超过90'})
        }
      }
    },
    confirm(){
      if(this.formInfo.taskArea == undefined){
        modal.warn({title: '提示', content: '执行区域不能为空'})
        return
      }
      if(this.formInfo.d0215 == undefined && this.formInfo.d0216 == undefined){
        modal.warn({title: '提示', content: '文保级别和巡查级别不可都为空'})
        return
      }
      if(this.formInfo.d0207 == '' || this.formInfo.d0207 == null){
        modal.warn({title: '提示', content: '计划类型不能为空'})
        return
      }
      if(this.formInfo.d0208 == '' || this.formInfo.d0208 == null){
        modal.warn({title: '提示', content: '执行频率不能为空'})
        return
      }
      if((this.formInfo.d0207!=1 && this.formInfo.d0208 != 1) && this.formInfo.d0209 == ''){
        modal.warn({title: '提示', content: '执行间隔不能为空'})
        return
      }
      /* if((this.formInfo.d0207 == 1 || this.formInfo.d0207 == 2) && this.formInfo.d0212 == ''){
         modal.warn({title: '提示', content: '是否跳过周末不能为空'})
         return
       }*/
      //专项任务校验表单
      for(let i=0;i<this.formInfo.specialFormVOS.length;i++){
        if(this.formInfo.specialFormVOS[i].d0802 == null || this.formInfo.specialFormVOS[i].d0802 == ''){
          modal.warn({title: '提示', content: '专项巡查类型不能为空'})
          return
        }
        if(this.formInfo.specialFormVOS[i].d0803 == null || this.formInfo.specialFormVOS[i].d0803 == ''){
          modal.warn({title: '提示', content: '专项巡查名称不能为空'})
          return
        }
        if(this.formInfo.specialFormVOS[i].optionList){
          for(let j=0;j<this.formInfo.specialFormVOS[i].optionList.length;j++){
            if(this.formInfo.specialFormVOS[i].optionList[j].d0902 == null || this.formInfo.specialFormVOS[i].optionList[j].d0902 == ''){
              modal.warn({title: '提示', content: '类型为单选或多选时，选项名称不能为空'})
              return
            }
          }
        }
      }

      const params = Object.assign(this.formInfo)
      setTimeout(() => {
        this.$http.post(getPatrolSettingRes, params).then((res) => {
          this.formInfo.d0206 = res.result.d0206
          this.formInfo.d0215Name = res.result.d0215Name
          this.formInfo.d0216Name = res.result.d0216Name
          this.formInfo.d0217Name = res.result.d0217Name
          this.formInfo.patrolFrequency = res.result.patrolFrequency
          this.formInfo.pointCount = res.result.pointCount
          this.formInfo.resourcesData = res.result.resourcesData
          if(this.pointFlag){
            this.$emit("handleCancelTwo")
            if(this.setPatrolDataTwo){
              this.setPatrolDataTwo(this.formInfo)
            }
          }else{
            this.$emit("handleCancel")
            if(this.setPatrolData){
              this.setPatrolData(this.formInfo)
            }
          }
/*          if(this.setPatrolData){
            this.setPatrolData(this.formInfo)
          }*/
        }).catch((error) => {
          console.log(JSON.stringify(error))
        }).finally(() =>{
        })
      }, 50)
    },
    handleCancel() {
      this.visible = false;
    },
    showOrHide() {
      this.visible = !this.visible;
    },
    handleOk() {
    },
    d0215Change(){
      this.d0216Disabled = this.formInfo.d0215 && this.formInfo.d0215.length > 0;
    },
    d0216Change(){
      this.d0215Disabled = this.formInfo.d0216 && this.formInfo.d0216.length>0;
    },
    taskAreaChange(){
      this.treeData = {  b0105:[],
        b0104:[],
        b0129:[],}
      this.dictData = {  b0105:[],
        b0104:[],
        b0129:[],}
      this.formInfo.d0215 = undefined
      this.formInfo.d0216 = undefined
      this.formInfo.d0217 = undefined
      this.d0215Change()
      this.d0216Change()
      this.getTreeData()
       this.$emit('event1', false)
    }
  }
}
</script>

<style scoped lang="less">
.list-item {
  display: flex;

  .list-item-index {
    width: 36px;
    font-size: 18px;
  }
}

.sub-form {
  margin-top: 15px;
}
</style>
